import http from '@ohos.net.http';
import prompt from '@system.prompt';
import router from '@system.router';

export default {
    data: {
        title: 'World',
        grade: '2',
        progressPercent: 20,
        progressColor: "#00ff00",
        bgColor: "#669966",
        percent: 90,
        kneading:'3.5',
        stretch:'2.6',
        tremble:'2.1',
        muscle:'3.4',
        returnContent: '',
        isRefreshing: false,
        lineData: [
            {
                strokeColor: '#0081ff',
                fillColor: '#cce5ff',
                data: [763, 550, 551, 554, 731, 654, 525, 696, 595, 628, 433, 431, 754, 643, 743, 654, 526, 654],
                gradient: true,
            }
        ],
        lineOps: {
            xAxis: {
                min: 0,
                max: 20,
                display: false,
            },
            yAxis: {
                min: 0,
                max: 1000,
                display: false,
            },
            series: {
                lineStyle: {
                    width: "2px",
                    smooth: true,
                },
                headPoint: {
                    shape: "circle",
                    size: 5,
                    strokeWidth: 5,
                    fillColor: '#ffffff',
                    strokeColor: '#007aff',
                    display: true,
                },
                loop: {
                    margin: 2,
                    gradient: true,
                }
            }
        },
    },

    onInit(){
        if(this.progressPercent>0 && this.progressPercent<=20){
            this.progressColor = "#b32ee72e"
        } else if (this.progressPercent>20 && this.progressPercent<=40){
            this.progressColor = "#80c8ff00"
        } else if (this.progressPercent>40 && this.progressPercent<=60){
            this.progressColor = "#80ffd500"
        } else if (this.progressPercent>60 && this.progressPercent<=80){
            this.progressColor = "#80ff7700"
        } else if (this.progressPercent>80){
            this.progressColor = "#80ff0000"
        }
    },
    launch4() {
        router.push ({
            uri: 'pages/niam/niam',
        });
    },
    launch5() {
        router.push ({
            uri: 'pages/action2/action2',
        });
    },
    launch6() {
        router.push ({
            uri: 'pages/pinggu/pinggu',
        });
    },
    refreshButton(){
        let httpRequest = http.createHttp();
        // 创建一个http，里面包括发起请求、中断请求、订阅/取消订阅HTTP Response Header 事件。
        // 每一个HttpRequest对象对应一个Http请求。如需发起多个Http请求，须为每个Http请求创建对应HttpRequest对象。
        //返回一个HttpRequest对象，里面包括request、destroy、on和off方法。

        let url = "http://49.4.115.226:8000/get_end_data?date=04-28";

        httpRequest.request(url, {
            // 注意请求方法：http.POST
            method: http.POST, // 可选，默认为http.RequestMethod.GET
        }, (err, data)=> {  // 判断是否请求成功
            if (!err) {  // 请求成功
                this.returnContent = JSON.parse(data.result);  //JSON.parse(字符串)——将字符串转换成json数据格式
                this.grade = this.returnContent.results[0].data.grade
                this.kneading = this.returnContent.results[0].data.Kneading
                this.stretch = this.returnContent.results[0].data.stretch
                this.tremble = this.returnContent.results[0].data.tremble
                this.muscle = this.returnContent.results[0].data.muscle
                this.last_update = this.returnContent.results[0].last_update
            } else {  // 请求失败
                prompt.showToast({
                    message: data.result,
                    duration: 3000,
                });
            }
        })
    },

    Pull_Down(e) {

        this.isRefreshing = e.refreshing;

        this.refreshButton();
        setTimeout(() => {
            this.isRefreshing = false;
            prompt.showToast({
                message: "刷新成功"
            })
        }, 1500)
    },

}